package com.learn.eduuserboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.learn.eduapi.entity.user.User;
import com.learn.eduapi.entity.user.UserAdmin;
import com.learn.eduuserboot.mapper.UserAdminDao;
import com.learn.eduuserboot.mapper.UserMapper;
import com.learn.eduuserboot.service.UserAdminService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class UserAdminServiceImpl implements UserAdminService {
    @Autowired
    private UserAdminDao userAdminDao;

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserAdmin selectById(Integer id) {
        return userAdminDao.selectById(id);
    }

    @Override
    public int updateUser(User user, Wrapper<User> userWrapper) {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = sdf.format(date);
        user.setUpdateTime(dateString);
        return userMapper.update(user,userWrapper);
    }

    @Override
    public int update(UserAdmin userAdmin, Wrapper<UserAdmin> userAdminWrapper) {
        return userAdminDao.update(userAdmin,userAdminWrapper);
    }

    @Override
    public UserAdmin login(String name) {
       return userAdminDao.selectByName(name);
    }
}
